home *** CD-ROM | disk | FTP | other *** search
/ Sprite 1984 - 1993 / Sprite 1984 - 1993.iso / src / machserver / 1.098 / mem / memSubr.c < prev   
C/C++ Source or Header  |  1990-10-11  |  4KB  |  190 lines

  1. /*
  2.  * memSubr.c --
  3.  *
  4.  *    This file contains user/kernel-dependent routines used by the
  5.  *    dynamic memory allocation system. It provides procedures
  6.  *    to allocate storage, and a panic routine to halt execution.
  7.  *
  8.  *    Every routine in this file assumes that the monitor lock is held.
  9.  *
  10.  * Copyright 1986 Regents of the University of California
  11.  * All rights reserved.
  12.  */
  13.  
  14. #ifndef lint
  15. static char rcsid[] = "$Header: /sprite/src/kernel/mem/RCS/memSubr.c,v 9.4 90/10/11 12:42:56 kupfer Exp $ SPRITE (Berkeley)";
  16. #endif /* not lint */
  17.  
  18. #include <sprite.h>
  19. #include <vm.h>
  20. #include <stdlib.h>
  21. #include <varargs.h>
  22. #include <mem.h>
  23. #include <memInt.h>
  24.  
  25. /*
  26.  * memPrintProc is the routine called by the routines in memory.c
  27.  * when they have something to print. It is set to PrintProc in
  28.  * MemProcInit().
  29.  */
  30.  
  31. static void     PrintProc _ARGS_(());
  32.  
  33. void (*memPrintProc) _ARGS_(());
  34.  
  35. ClientData    memPrintData = (ClientData) 0;
  36.  
  37. /*
  38.  * Flag to determine whether to panic when freeing free blocks. This
  39.  * value is user/kernel dependent and is therefore placed in this file.
  40.  */
  41.  
  42. Boolean memAllowFreeingFree = FALSE;
  43.  
  44.  
  45.  
  46. /*
  47.  *----------------------------------------------------------------------
  48.  *
  49.  * MemPanic --
  50.  *
  51.  *    MemPanic is a procedure that's called by the memory allocator
  52.  *    when it has uncovered a fatal error.  MemPanic prints the
  53.  *    message and aborts.  It does NOT return.
  54.  *
  55.  * Results:
  56.  *    None.
  57.  *
  58.  * Side effects:
  59.  *    The program is exited.
  60.  *
  61.  *----------------------------------------------------------------------
  62.  */
  63.  
  64. void
  65. MemPanic(message)
  66.     char *message;
  67. {
  68.     panic(message);
  69. }
  70.  
  71.  
  72. /*
  73.  *----------------------------------------------------------------------
  74.  *
  75.  * MemChunkAlloc --
  76.  *
  77.  *    Mem_Alloc will call MemChunkAlloc to get another region of storage
  78.  *    from the system (i.e. whenever the storage it's gotten so far
  79.  *    is insufficient to meet a request).  The actual size returned
  80.  *    may be greater than size but not less.  This region now becomes
  81.  *    the permanent property of Mem_Alloc, and will never be returned.
  82.  *
  83.  * Results:
  84.  *    The actual size of the block allocated in bytes.
  85.  *
  86.  * Side effects:
  87.  *    Memory is passed to the allocator and lost forever.
  88.  *
  89.  *----------------------------------------------------------------------
  90.  */
  91.  
  92. int
  93. MemChunkAlloc(size, addressPtr)
  94.     int size;            /* Number of bytes desired.  */
  95.     Address *addressPtr;    /* Address of the new region */
  96. {
  97.     *addressPtr = Vm_RawAlloc(size);
  98.     return(size);
  99. }
  100.  
  101. /*
  102.  *----------------------------------------------------------------------
  103.  *
  104.  * Mem_DumpStats --
  105.  *
  106.  *    Call back routine used to print memory stats with
  107.  *    a magic 'L1-m' keystroke on the console.
  108.  *
  109.  * Results:
  110.  *    None.
  111.  *
  112.  * Side effects:
  113.  *    Stuff is printed on the console.
  114.  *
  115.  *----------------------------------------------------------------------
  116.  */
  117. static    int    smallMinNum = 1;
  118. static    int    largeMinNum = 1;
  119. static    int    largeMaxSize = 10000;
  120.  
  121. /* ARGSUSED */
  122. void
  123. Mem_DumpStats(dummy)
  124.     ClientData dummy;
  125. {
  126.     Mem_PrintStatsSubrInt(PrintProc, (ClientData) 0, smallMinNum, largeMinNum,
  127.         largeMaxSize);
  128.     Mem_DumpTrace(-1);
  129. }
  130.  
  131.  
  132. /*
  133.  *----------------------------------------------------------------------
  134.  *
  135.  * PrintProc --
  136.  *
  137.  *    The default printing routine for the kernel.
  138.  *
  139.  * Results:
  140.  *    None.
  141.  *
  142.  * Side effects:
  143.  *    None.
  144.  *
  145.  *----------------------------------------------------------------------
  146.  */
  147. /*ARGSUSED*/
  148. static void
  149. PrintProc(va_alist)
  150.     va_dcl        /* ClientData, then char *format, then any number
  151.              * of additional values to be printed. */
  152. {
  153.     ClientData clientData;
  154.     char *format;
  155.     va_list args;
  156.  
  157.     va_start(args);
  158.     clientData = va_arg(args, ClientData);
  159. #ifdef lint
  160.     clientData = clientData;
  161. #endif /* lint */
  162.     format = va_arg(args, char *);
  163.     (void)vprintf(format, args);
  164.     va_end(args);
  165. }
  166.  
  167.  
  168. /*
  169.  *----------------------------------------------------------------------
  170.  *
  171.  * MemPrintInit --
  172.  *
  173.  *    Initializes the default printing routine.
  174.  *
  175.  * Results:
  176.  *    None.
  177.  *
  178.  * Side effects:
  179.  *    The default printing routine is initialized.
  180.  *
  181.  *----------------------------------------------------------------------
  182.  */
  183.  
  184. void
  185. MemPrintInit()
  186. {
  187.     memPrintProc = PrintProc;
  188.     memPrintData = (ClientData) 0;
  189. }
  190.